package com.hrsoft.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.hrsoft.common.utils.PageUtils;
import com.hrsoft.common.utils.R;
import com.hrsoft.common.utils.ShiroUtils;
import com.hrsoft.modules.sys.entity.SysItemdetailsEntity;
import com.hrsoft.modules.sys.service.SysItemdetailsService;
import com.hrsoft.modules.sys.entity.SysUserEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 
 *
 * @author garfield.yue
 * @email yuedefeng101@163.com
 * @date 2020-03-19 20:51:35
 */
@RestController
@RequestMapping("sys/sysitemdetails")
public class SysItemdetailsController {
    @Autowired
    private SysItemdetailsService sysItemdetailsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sysitemdetails:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysItemdetailsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:sysitemdetails:info")
    public R info(@PathVariable("id") Long id){
		SysItemdetailsEntity sysItemdetails = sysItemdetailsService.getById(id);

        return R.ok().put("sysItemdetails", sysItemdetails);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:sysitemdetails:save")
    public R save(@RequestBody SysItemdetailsEntity sysItemdetails){
        SysUserEntity user = ShiroUtils.getUserEntity();
        sysItemdetails.setCreatedOn(new Date());
        sysItemdetails.setCreatedBy(user.getFullName());
        sysItemdetails.setCreateUserId(user.getUserId().intValue());
		sysItemdetailsService.save(sysItemdetails);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:sysitemdetails:update")
    public R update(@RequestBody SysItemdetailsEntity sysItemdetails){
        SysUserEntity user = ShiroUtils.getUserEntity();
        sysItemdetails.setModifiedOn(new Date());
        sysItemdetails.setModifiedBy(user.getFullName());
        sysItemdetails.setModifiedUserId(user.getUserId().intValue());
		sysItemdetailsService.updateById(sysItemdetails);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sysitemdetails:delete")
    public R delete(@RequestBody Long[] ids){
		sysItemdetailsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
